package fr.norsys.mapper.console.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import uk.ltd.getahead.dwr.ExecutionContext;
import fr.norsys.mapper.console.model.Attribute;
import fr.norsys.mapper.console.model.ConsoleCst;
import fr.norsys.mapper.console.model.Resource;
import fr.norsys.mapper.console.service.ApplicationService;
import fr.norsys.mapper.console.service.AttributeService;
import fr.norsys.mapper.console.service.PropertyServiceImpl;
import fr.norsys.mapper.console.service.ResourceService;

public class AttributeServiceDWR {
	private final static Log log = LogFactory.getLog(PropertyServiceImpl.class);

	private ApplicationService applicationService;

	private ResourceService resourceService;

	private AttributeService attributeService;

	AttributeServiceDWR() {
		super();
	}

	/**
	 * Action to save an attribute in session
	 * 
	 * @param attribute
	 */
	public void save(Attribute attr) throws Exception {
		Attribute attribute = attr;
		Resource currentResource = (Resource) ExecutionContext.get()
				.getSession().getAttribute(ConsoleCst.CURRENT_RESOURCE);
		attributeService.save(attribute, currentResource);
		ExecutionContext.get().getSession().setAttribute(
				ConsoleCst.IS_APPLICATION_MODIFIED,
				ConsoleCst.APPLICATION_MODIFIED);
	}

	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}

	public ApplicationService getApplicationService() {
		return applicationService;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	public ResourceService getResourceService() {
		return resourceService;
	}

	public AttributeService getAttributeService() {
		return attributeService;
	}

	public void setAttributeService(AttributeService attributeService) {
		this.attributeService = attributeService;
	}

}
